package sjtu.ist.warehouse4ws.action.file;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.mgt.DefaultSecurityManager;
import org.apache.shiro.subject.Subject;
import org.apache.struts2.json.annotations.JSON;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
import org.xml.sax.SAXException;

import sjtu.ist.warehouse4ws.epc2bpmn.ParserEpc;
import sjtu.ist.warehouse4ws.jcr.RepositoryMoudl;
import sjtu.ist.warehouse4ws.model.CustDepartment;
import sjtu.ist.warehouse4ws.model.CustDomainmodelstate;
import sjtu.ist.warehouse4ws.model.CustEpcunit;
import sjtu.ist.warehouse4ws.model.CustEpcunits;
import sjtu.ist.warehouse4ws.model.CustFileinfo;
import sjtu.ist.warehouse4ws.model.CustFunctionpoint;
import sjtu.ist.warehouse4ws.model.CustModelgroup;
import sjtu.ist.warehouse4ws.model.CustPermission;
import sjtu.ist.warehouse4ws.model.CustPermissionresources;
import sjtu.ist.warehouse4ws.model.CustResource;
import sjtu.ist.warehouse4ws.model.CustRole;
import sjtu.ist.warehouse4ws.model.CustRolepermissions;
import sjtu.ist.warehouse4ws.model.Department;
import sjtu.ist.warehouse4ws.model.Domainmodelstate;
import sjtu.ist.warehouse4ws.model.Epcunit;
import sjtu.ist.warehouse4ws.model.Epcunits;
import sjtu.ist.warehouse4ws.model.Fileinfo;
import sjtu.ist.warehouse4ws.model.Functionpoint;
import sjtu.ist.warehouse4ws.model.Functions;
import sjtu.ist.warehouse4ws.model.Modelgroup;
import sjtu.ist.warehouse4ws.model.Oplog;
import sjtu.ist.warehouse4ws.model.Permission;
import sjtu.ist.warehouse4ws.model.Permissionresources;
import sjtu.ist.warehouse4ws.model.Resource;
import sjtu.ist.warehouse4ws.model.Role;
import sjtu.ist.warehouse4ws.model.Rolepermissions;
import sjtu.ist.warehouse4ws.model.ShiroUser;
import sjtu.ist.warehouse4ws.security.MyRealm;
import sjtu.ist.warehouse4ws.service.DepartmentService;
import sjtu.ist.warehouse4ws.service.FileInfoService;
import sjtu.ist.warehouse4ws.service.ModelgroupService;
import sjtu.ist.warehouse4ws.service.OplogService;
import sjtu.ist.warehouse4ws.service.PermissionService;
import sjtu.ist.warehouse4ws.service.PermissionresourcesService;
import sjtu.ist.warehouse4ws.service.ResourceService;
import sjtu.ist.warehouse4ws.service.RoleService;
import sjtu.ist.warehouse4ws.service.RolepermissionsService;
import sjtu.ist.warehouse4ws.service.ShiroUserService;
import sjtu.ist.warehouse4ws.service.cust.CustDepartmentService;
import sjtu.ist.warehouse4ws.service.cust.CustFileInfoService;
import sjtu.ist.warehouse4ws.service.cust.CustModelgroupService;
import sjtu.ist.warehouse4ws.service.cust.CustPermissionService;
import sjtu.ist.warehouse4ws.service.cust.CustPermissionresourcesService;
import sjtu.ist.warehouse4ws.service.cust.CustResourceService;
import sjtu.ist.warehouse4ws.service.cust.CustRoleService;
import sjtu.ist.warehouse4ws.service.cust.CustRolepermissionsService;
import sjtu.ist.warehouse4ws.tool.BaseAction;
import sjtu.ist.warehouse4ws.tool.Constants;
import sjtu.ist.warehouse4ws.tool.MyUtils;
import sjtu.ist.warehouse4ws.tool.ParseDomainModel;
import sjtu.ist.warehouse4ws.tool.ParserFunctionpoint;
import sjtu.ist.warehouse4ws.tool.ParserOrg;
import sjtu.ist.warehouse4ws.tool.ParserProcess;
import sjtu.ist.warehouse4ws.tool.PropertyHelper;
import sjtu.ist.warehouse4ws.tool.file.ModelPackage;

import com.opensymphony.xwork2.ActionContext;

public class FileAction extends BaseAction {
	private static final long serialVersionUID = 3721331665423453270L;
	private Map<String, Object> infos = new HashMap<String, Object>();
	private FileInfoService fileInfoService;
	private CustFileInfoService custFileInfoService;
	public static final String ROOT = "upload\\";
	private ShiroUserService shiroUserService;
	private RepositoryMoudl repositoryMoudlService;
	private OplogService oplogService;

	private File myUpload;

	private String isConsistence = "~错误：请上传";
	private String isDepartment = "";

	private String zipConsistence = "";

	private static String tmpresult = "~错误：缺少";;

	private String myUploadContentType;

	private int allUpload;
	private String fileName;
	private String did;
	private String dname;
	private String rname;
	private String dproject;
	private String dtype;
	private String dfileState;

	private String userName;
//
//	private static List<Fileinfo> tempOtherModel = new ArrayList<Fileinfo>();
//	private static List<CustFileinfo> tempOtherCustModel = new ArrayList<CustFileinfo>();

	private PermissionService permissionService;
	private PermissionresourcesService permissionresourcesService;
	private RoleService roleService;
	private RolepermissionsService rolepermissionsService;
	private DepartmentService departmentService;
	private ResourceService resourceService;
	private ModelgroupService modelgroupService;

	private CustPermissionService custPermissionService;
	private CustPermissionresourcesService custPermissionresourcesService;
	private CustRoleService custRoleService;
	private CustRolepermissionsService custRolepermissionsService;
	private CustDepartmentService custDepartmentService;
	private CustResourceService custResourceService;
	private boolean success;

	private String id;
	private int type;

	private RepositoryMoudl repositoryMoudl;
	public MyRealm myRealm;

	public void setRepositoryMoudl(RepositoryMoudl repositoryMoudl) {
		this.repositoryMoudl = repositoryMoudl;
	}

//	public static List<Fileinfo> getTempOtherModel() {
//		return tempOtherModel;
//	}
//
//	public static void setTempOtherModel(List<Fileinfo> tempOtherModel) {
//		FileAction.tempOtherModel = tempOtherModel;
//	}

	public static String getTmpresult() {
		return tmpresult;
	}

	public static void setTmpresult(String tmpresult) {
		FileAction.tmpresult = tmpresult;
	}

	public List<Fileinfo> otherModel = new ArrayList<Fileinfo>();

	public String getDid() {
		return did;
	}

	public void setDid(String did) {
		this.did = did;
	}

	public String getDname() {
		return dname;
	}

	public void setDname(String dname) {
		this.dname = dname;
	}

	public String getRname() {
		return rname;
	}

	public void setRname(String rname) {
		this.rname = rname;
	}

	public String getDproject() {
		return dproject;
	}

	public void setDproject(String dproject) {
		this.dproject = dproject;
	}

	public String getDtype() {
		return dtype;
	}

	public void setDtype(String dtype) {
		this.dtype = dtype;
	}

	public String getDfileState() {
		return dfileState;
	}

	public void setDfileState(String dfileState) {
		this.dfileState = dfileState;
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public void setCustPermissionService(
			CustPermissionService custPermissionService) {
		this.custPermissionService = custPermissionService;
	}

	public void setCustPermissionresourcesService(
			CustPermissionresourcesService custPermissionresourcesService) {
		this.custPermissionresourcesService = custPermissionresourcesService;
	}

	public void setCustRoleService(CustRoleService custRoleService) {
		this.custRoleService = custRoleService;
	}

	public void setCustRolepermissionsService(
			CustRolepermissionsService custRolepermissionsService) {
		this.custRolepermissionsService = custRolepermissionsService;
	}

	public void setCustDepartmentService(
			CustDepartmentService custDepartmentService) {
		this.custDepartmentService = custDepartmentService;
	}

	public void setCustResourceService(CustResourceService custResourceService) {
		this.custResourceService = custResourceService;
	}

	public void setCustModelgroupService(
			CustModelgroupService custModelgroupService) {
		this.custModelgroupService = custModelgroupService;
	}

	private CustModelgroupService custModelgroupService;

	public void setModelgroupService(ModelgroupService modelgroupService) {
		this.modelgroupService = modelgroupService;
	}

	public void setResourceService(ResourceService resourceService) {
		this.resourceService = resourceService;
	}

	public void setPermissionService(PermissionService permissionService) {
		this.permissionService = permissionService;
	}

	public void setPermissionresourcesService(
			PermissionresourcesService permissionresourcesService) {
		this.permissionresourcesService = permissionresourcesService;
	}

	public void setRoleService(RoleService roleService) {
		this.roleService = roleService;
	}

	public void setRolepermissionsService(
			RolepermissionsService rolepermissionsService) {
		this.rolepermissionsService = rolepermissionsService;
	}

	public void setDepartmentService(DepartmentService departmentService) {
		this.departmentService = departmentService;
	}

	public int getAllUpload() {
		return allUpload;
	}

	public void setAllUpload(int allUpload) {
		this.allUpload = allUpload;
	}

	private String myUploadFileName;

	private String path;

	static List<Fileinfo> checkConsistence = new ArrayList<Fileinfo>();
	static List<CustFileinfo> checkConsistenceForCust = new ArrayList<CustFileinfo>();

	public static List<Fileinfo> getCheckConsistence() {
		return checkConsistence;
	}

	public static List<CustFileinfo> getCheckConsistenceForCust() {
		return checkConsistenceForCust;
	}
	
	public static void setCheckConsistence(List<Fileinfo> checkConsistence) {
		FileAction.checkConsistence = checkConsistence;
	}

	public static void setCheckConsistenceForCust(List<CustFileinfo> checkConsistenceForCust) {
		FileAction.checkConsistenceForCust = checkConsistenceForCust;
	}
	
	static List<Fileinfo> checkDepartment = new ArrayList<Fileinfo>();

	public static List<Fileinfo> getCheckDepartment() {
		return checkDepartment;
	}

	static List<CustFileinfo> checkCustDepartment = new ArrayList<CustFileinfo>();

	public static List<CustFileinfo> getCheckDepartmentForCust() {
		return checkCustDepartment;
	}

	public static void setCheckDepartment(List<Fileinfo> checkDepartment) {
		FileAction.checkDepartment = checkDepartment;
	}

	public static void setCheckDepartmentForCust(
			List<CustFileinfo> checkDepartment) {
		FileAction.checkCustDepartment = checkDepartment;
	}

	/**
	 * 上传文件
	 * 
	 * @return
	 * @throws ParserConfigurationException
	 * @throws SAXException
	 * 
	 * @throws IOException
	 */
	
	
	public String uploadPackage() {
		String rootPath = getSession().getServletContext().getRealPath("/");
		rootPath += ROOT;
		DefaultSecurityManager securityManager = new DefaultSecurityManager();
		securityManager.setRealm(myRealm);
		SecurityUtils.setSecurityManager(securityManager);

		ShiroUser user = shiroUserService.findUser(userName);
		int companyId = user.getCompanyId();

		ActionContext ac = ActionContext.getContext();
		Map<String, Object> session = ac.getSession();
		session.put("companyId", companyId);
		
		String groupId="";

		if (Constants.ADMIN_COMPANY_ID == companyId) {

			String uploadFileName = getMyUploadFileName();
			ModelPackage mp = new ModelPackage();
			int last = uploadFileName.lastIndexOf(".");
			String sp = rootPath;
			String group = uploadFileName.substring(0, last);
			int groupInt;


			Modelgroup modelgroup = new Modelgroup();
			String des = "";
			if (des.length() != 0) {
				modelgroup.setDescription(des);
			}
			modelgroup.setGroupName(group);
			groupInt = modelgroupService.save(modelgroup,companyId);
			groupId = groupInt + "";
			MyUtils.mkDirectory(sp);	
			
			MyUtils.upload(uploadFileName, sp, getMyUpload());
			mp.unzipPackage(getMyUpload(), sp+groupId+"\\");
			
			//存入模型库
			repositoryMoudlService.saveModelgroup(sp+groupId+"\\",String.valueOf(companyId),group);
			//提取模型版本号
			String version=repositoryMoudlService.getVersion(String.valueOf(companyId),group);
			
			modelgroup.setVersion(version);
			modelgroupService.update(modelgroup,companyId);
			
			
			if (mp.processFiles.size() == 0)
				tmpresult += "功能结构模型 ";
			if (mp.functionFiles.size() == 0)
				tmpresult += "功能模型 ";
			if (mp.organizationFiles.size() == 0)
				tmpresult += "组织模型 ";
			if (mp.domainFiles.size() == 0)
				tmpresult += "业务对象模型 ";
			if (mp.epcFiles.size() == 0)
				tmpresult += "epc模型 ";

			List<Fileinfo> domain = new ArrayList<Fileinfo>();

			for (File f : mp.domainFiles) {
				Fileinfo fileinfo = new Fileinfo();
				fileinfo.setXmlpath(f.getAbsolutePath());
				fileinfo.setName(f.getName());
				fileinfo.setId(java.util.UUID.randomUUID().toString());
				fileinfo.setProject(group);
				fileinfo.setType(4);
				fileinfo.setGroupId(groupId);
				fileinfo.setVersionId(version);
				domain.add(fileinfo);
				fileInfoService.saveFileInfo(fileinfo,companyId);
				checkConsistence.add(fileinfo);

			}

			if (tmpresult.equals("~错误：缺少"))
				tmpresult = "";
			List<Domainmodelstate> domainStateEPC = new ArrayList<Domainmodelstate>();
			for (Fileinfo i : domain) {
				try {

					ParseDomainModel pdm = new ParseDomainModel();
					ArrayList<Domainmodelstate> dmodelstate = pdm
							.reserveState(i.getXmlpath()); // 抽取所有业务对象模型的状态模型
					for (Domainmodelstate ds : dmodelstate) {
						domainStateEPC.add(ds);
					}
					if (checkDM(i.getXmlpath()) != "") {
						tmpresult += "~错误：" + checkDM(i.getXmlpath())
								+ "业务对象文件没有上传"; // 检测复杂业务对象模型 看是否都已上传
					}

				} catch (ParserConfigurationException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (SAXException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();

				}
			}
			
			
			HashMap<String, Integer> functionPoint = new HashMap<String, Integer>();
			List<Functionpoint> functionEpc = new ArrayList<Functionpoint>();
			for (File f : mp.functionFiles) {
				Fileinfo fileinfo = new Fileinfo();
				fileinfo.setXmlpath(f.getAbsolutePath());
				fileinfo.setName(f.getName());
				fileinfo.setId(java.util.UUID.randomUUID().toString());
				fileinfo.setProject(group);
				fileinfo.setType(2);
				fileinfo.setVersionId(version);
				fileinfo.setGroupId(groupId);
				fileInfoService.saveFileInfo(fileinfo,companyId);

				ParserFunctionpoint pfp = new ParserFunctionpoint();
				Functionpoint fp = pfp.reservePoint(f.getAbsolutePath()); // 抽取所有功能点
				functionPoint.put(fp.getId(), 0);
				functionEpc.add(fp);
				checkConsistence.add(fileinfo);

			}
			for (File f : mp.processFiles) {
				Fileinfo fileinfo = new Fileinfo();
				fileinfo.setXmlpath(f.getAbsolutePath());
				fileinfo.setName(f.getName());
				fileinfo.setId(java.util.UUID.randomUUID().toString());
				fileinfo.setProject(group);
				fileinfo.setType(1);
				fileinfo.setVersionId(version);
				fileinfo.setGroupId(groupId);

				fileInfoService.saveFileInfo(fileinfo,companyId);
				checkConsistence.add(fileinfo);
				ParserProcess pp = new ParserProcess();

				ArrayList<Functions> fs = pp.reserveFunctions(f
						.getAbsolutePath());

				for (Functions functions : fs) { // 检测流程文件的功能点是否都已上传
					String fId = functions.getFunctionid();
					if (functionPoint.containsKey(fId))
						functionPoint.put(fId, 1);
					else
						tmpresult += "~错误：" + fId + "功能文件没有上传";
				}
			}

			if (functionPoint.containsValue(0)) {
				tmpresult += "~警告：";
				// 采用Iterator遍历HashMap
				Iterator it = functionPoint.keySet().iterator();
				while (it.hasNext()) {

					String key = (String) it.next();

					if (functionPoint.get(key) == 0)
						tmpresult += key + " ";
				}
				tmpresult += "没有对应的流程文件，请检查是否还有未上传的流程文件"; // 检测是否有未包含在流程的功能点模型

			}
			for (File f : mp.organizationFiles) {
				Fileinfo fileinfo = new Fileinfo();
				fileinfo.setXmlpath(f.getAbsolutePath());
				fileinfo.setName(f.getName());
				fileinfo.setId(java.util.UUID.randomUUID().toString());
				fileinfo.setProject(group);
				fileinfo.setVersionId(version);
			    fileinfo.setGroupId(groupId);
				fileinfo.setType(3);

//				List<Fileinfo> isExist = fileInfoService.findFileId(
//						fileinfo.getName(), fileinfo.getProject(), 3); // 先根据名称和项目查询
//																		// 是否已存在类似项目
			//	if (isExist.toString() == "[]") {
					fileInfoService.saveFileInfo(fileinfo,companyId);

					int deptNotParse = 0;
					ParserOrg parserOrg = new ParserOrg();
					List<Department> departmentList = parserOrg
							.parseDepartment(f.getAbsolutePath()); // 解析并存储部门
					for (Department department : departmentList) {
						department.setFileId(fileinfo.getId());
						department.setUid(java.util.UUID.randomUUID()
								.toString());
						department.setGroupId(groupId);
						department.setVersionId(version);
						deptNotParse = 1;
					}
					if (deptNotParse == 1)
						departmentService.save(departmentList,companyId);
					int permNotParse = 0;
					List<Permission> permissionList = parserOrg
							.parsePermission(f.getAbsolutePath()); // 解析并存储权限
					for (Permission permission : permissionList) {
						permNotParse = 1;
						permission.setFileId(fileinfo.getId());
						permission.setUid(java.util.UUID.randomUUID()
								.toString());
						permission.setGroupId(groupId);
						permission.setVersionId(version);
						permissionService.addPermission(permission,companyId);
					}
					int recNotParse = 0;
					List<Resource> resourceList = parserOrg.parseResource(f
							.getAbsolutePath()); // 解析并存储资源
					for (Resource resource : resourceList) {
						recNotParse = 1;
						resource.setFileId(fileinfo.getId());
						resource.setUid(java.util.UUID.randomUUID().toString());
						resource.setGroupId(groupId);
						resource.setVersionId(version);
						resourceService.addResource(resource,companyId);
					}
					int roleNotParse = 0;
					List<Role> roleList = parserOrg.parseRole(f
							.getAbsolutePath()); // 解析并存储角色
					for (Role role : roleList) {

						roleNotParse = 1;
						role.setFileId(fileinfo.getId());
						role.setUid(java.util.UUID.randomUUID().toString());
						role.setGroupId(groupId);
						role.setVersionId(version);
						roleService.addRole(role,companyId);
						// }
					}

					if (roleNotParse == 1 && permNotParse == 1) {
						List<Rolepermissions> rolepermissionsList = parserOrg
								.parseRolepermissions(f.getAbsolutePath()); // 解析并存储角色权限
						for (Rolepermissions rolepermissions : rolepermissionsList) {
							rolepermissions.setGroupId(groupId);
							rolepermissions.setVersionId(version);
							rolepermissionsService
									.addRolepermissions(rolepermissions,companyId);
						}

					}

					if (permNotParse == 1 && recNotParse == 1) {
						List<Permissionresources> permissionresourcesList = parserOrg
								.parsePermissionresources(f.getAbsolutePath());
						for (Permissionresources permissionresources : permissionresourcesList) {
							permissionresources.setGroupId(groupId);
							permissionresources.setVersionId(version);// 解析并纯初权限资源
							permissionresourcesService
									.addPermissionresources(permissionresources,companyId);
						}

					}
					this.success = true;
				//}
			}
			for (File f : mp.epcFiles) {
				Fileinfo fileinfo = new Fileinfo();
				fileinfo.setXmlpath(f.getAbsolutePath());
				fileinfo.setName(f.getName());
				fileinfo.setId(java.util.UUID.randomUUID().toString());
				fileinfo.setProject(group);
				fileinfo.setType(5);
				fileinfo.setVersionId(version);
				fileinfo.setGroupId(groupId);

				fileInfoService.saveFileInfo(fileinfo,companyId);
				checkConsistence.add(fileinfo);

				String result = this.checkEpcConsistence(f.getAbsolutePath(),
						domainStateEPC, functionEpc);

				tmpresult += result; // 检测EPC模型一致性

			}

			this.success = true;

		} else {
			try {
				groupId=uploadPackageForCust(companyId);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		
		//插入记录
		Oplog oplog=new Oplog();
		oplog.setGroupId(groupId);
		oplog.setUser(userName);
		oplog.setOperation(Oplog.upload);
		oplog.setDiscription("上传模型");
		oplogService.insertOplog(oplog);
		
		return SUCCESS;

	}

	public String uploadPackageForCust(int companyId) throws SAXException,
			ParserConfigurationException, IOException {
		String rootPath = getSession().getServletContext().getRealPath("/");
		rootPath += ROOT;

		String uploadFileName = getMyUploadFileName();
		ModelPackage mp = new ModelPackage();
		int last = uploadFileName.lastIndexOf(".");
		String sp = rootPath;
		String group = uploadFileName.substring(0, last);
		int groupInt;

		CustModelgroup modelgroup = new CustModelgroup();
		
		Modelgroup mg=new Modelgroup();
		PropertyHelper.copyProperties(modelgroup, mg);
		
		String des = "";
		if (des.length() != 0) {
			modelgroup.setDescription(des);
		}
		modelgroup.setGroupName(group);
		groupInt = modelgroupService.save(mg,companyId);
		String groupId = groupInt + "";
		MyUtils.mkDirectory(sp);	
		
		MyUtils.upload(uploadFileName, sp, getMyUpload());
		mp.unzipPackage(getMyUpload(), sp+groupId+"\\");
		
		//存入模型库
		repositoryMoudlService.saveModelgroup(sp+groupId+"\\",String.valueOf(companyId),group);
		//提取模型版本号
		String version=repositoryMoudlService.getVersion(String.valueOf(companyId),group);
		
		modelgroup.setVersion(version);
		custModelgroupService.update(modelgroup);

		
		
		if (mp.processFiles.size() == 0)
			tmpresult += "功能结构模型 ";
		if (mp.functionFiles.size() == 0)
			tmpresult += "功能模型 ";
		if (mp.organizationFiles.size() == 0)
			tmpresult += "组织模型 ";
		if (mp.domainFiles.size() == 0)
			tmpresult += "业务对象模型 ";
		if (mp.epcFiles.size() == 0)
			tmpresult += "epc模型 ";

		List<CustFileinfo> domain = new ArrayList<CustFileinfo>();

		for (File f : mp.domainFiles) {
			CustFileinfo fileinfo = new CustFileinfo();
			fileinfo.setXmlpath(f.getAbsolutePath());
			fileinfo.setName(f.getName());
			fileinfo.setId(java.util.UUID.randomUUID().toString());
			fileinfo.setProject(group);
			fileinfo.setType(4);
			fileinfo.setGroupId(groupId);
			fileinfo.setVersion(version);
			domain.add(fileinfo);
			fileInfoService.saveFileInfo(fileinfo,Constants.ADMIN_COMPANY_ID);
			checkConsistenceForCust.add(fileinfo);

		}

		if (tmpresult.equals("~错误：缺少"))
			tmpresult = "";
		List<CustDomainmodelstate> domainStateEPC = new ArrayList<CustDomainmodelstate>();
		for (Fileinfo i : domain) {
			try {

				ParseDomainModel pdm = new ParseDomainModel();
				ArrayList<Domainmodelstate> dmodelstate = pdm.reserveState(i
						.getXmlpath()); // 抽取所有业务对象模型的状态模型
				for (Domainmodelstate ds : dmodelstate) {
					CustDomainmodelstate cds = new CustDomainmodelstate();
					cds.setId(ds.getId());
					cds.setCnName(ds.getCnName());
					cds.setDescription(ds.getDescription());
					cds.setDomainModelid(ds.getDomainModelid());
					cds.setEnName(ds.getEnName());
					cds.setGroupId(ds.getGroupId());
					cds.setUid(ds.getUid());
					cds.setVersionId(ds.getVersionId());
					domainStateEPC.add(cds);
				}
				if (checkDM(i.getXmlpath()) != "") {
					tmpresult += "~错误：" + checkDM(i.getXmlpath())
							+ "业务对象文件没有上传"; // 检测复杂业务对象模型 看是否都已上传
				}

			} catch (ParserConfigurationException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (SAXException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();

			}
		}
		HashMap<String, Integer> functionPoint = new HashMap<String, Integer>();
		List<CustFunctionpoint> functionEpc = new ArrayList<CustFunctionpoint>();
		for (File f : mp.functionFiles) {
			CustFileinfo fileinfo = new CustFileinfo();
			fileinfo.setXmlpath(f.getAbsolutePath());
			fileinfo.setName(f.getName());
			fileinfo.setId(java.util.UUID.randomUUID().toString());
			fileinfo.setProject(group);
			fileinfo.setType(2);
			fileinfo.setGroupId(groupId);
			custFileInfoService.saveCustFileInfo(fileinfo);

			ParserFunctionpoint pfp = new ParserFunctionpoint();
			Functionpoint fp = pfp.reservePoint(f.getAbsolutePath()); // 抽取所有功能点

			functionPoint.put(fp.getId(), 0);
			CustFunctionpoint cfp = new CustFunctionpoint();
			cfp.setCnName(fp.getCnName());
			cfp.setDescription(fp.getDescription());
			cfp.setEnName(fp.getEnName());
			cfp.setFileId(fp.getFileId());
			cfp.setGroupId(fp.getGroupId());
			cfp.setId(fp.getId());
			cfp.setUid(fp.getUid());
			cfp.setVersionId(fp.getVersionId());
			functionEpc.add(cfp);
			checkConsistenceForCust.add(fileinfo);

		}
		for (File f : mp.processFiles) {
			CustFileinfo fileinfo = new CustFileinfo();
			fileinfo.setXmlpath(f.getAbsolutePath());
			fileinfo.setName(f.getName());
			fileinfo.setId(java.util.UUID.randomUUID().toString());
			fileinfo.setProject(group);
			fileinfo.setType(1);
			fileinfo.setGroupId(groupId);

			custFileInfoService.saveCustFileInfo(fileinfo);
			checkConsistenceForCust.add(fileinfo);
			ParserProcess pp = new ParserProcess();

			ArrayList<Functions> fs = pp.reserveFunctions(f.getAbsolutePath());

			for (Functions functions : fs) { // 检测流程文件的功能点是否都已上传
				String fId = functions.getFunctionid();
				if (functionPoint.containsKey(fId))
					functionPoint.put(fId, 1);
				else
					tmpresult += "~错误：" + fId + "功能文件没有上传";
			}
		}

		if (functionPoint.containsValue(0)) {
			tmpresult += "~警告：";
			// 采用Iterator遍历HashMap
			Iterator it = functionPoint.keySet().iterator();
			while (it.hasNext()) {

				String key = (String) it.next();

				if (functionPoint.get(key) == 0)
					tmpresult += key + " ";
			}
			tmpresult += "没有对应的流程文件，请检查是否还有未上传的流程文件"; // 检测是否有未包含在流程的功能点模型

		}
		for (File f : mp.organizationFiles) {
			CustFileinfo fileinfo = new CustFileinfo();
			fileinfo.setXmlpath(f.getAbsolutePath());
			fileinfo.setName(f.getName());
			fileinfo.setId(java.util.UUID.randomUUID().toString());
			fileinfo.setProject(group);
			fileinfo.setType(3);

			List<CustFileinfo> isExist = custFileInfoService.findFileId(
					fileinfo.getName(), fileinfo.getProject(), 3); // 先根据名称和项目查询
																	// 是否已存在类似项目
			if (isExist.toString() == "[]") {
				custFileInfoService.saveCustFileInfo(fileinfo);

				int deptNotParse = 0;
				ParserOrg parserOrg = new ParserOrg();
				List<Department> departmentList = parserOrg.parseDepartment(f
						.getAbsolutePath()); // 解析并存储部门
				for (Department department : departmentList) {
					department.setFileId(fileinfo.getId());
					department.setUid(java.util.UUID.randomUUID().toString());
					department.setGroupId(groupId);
					deptNotParse = 1;
				}
				List<CustDepartment> cdl = new ArrayList<CustDepartment>();
				for (Department d : departmentList) {
					CustDepartment cd = new CustDepartment();
					cd.setCnName(d.getCnName());
					cd.setEnName(d.getEnName());
					cd.setFileId(d.getFileId());
					cd.setGroupId(d.getGroupId());
					cd.setId(d.getId());
					cd.setParentName(d.getParentName());
					cd.setUid(d.getUid());
					cdl.add(cd);
				}
				if (deptNotParse == 1)
					custDepartmentService.save(cdl);
				int permNotParse = 0;
				List<Permission> permissionList = parserOrg.parsePermission(f
						.getAbsolutePath()); // 解析并存储权限
				for (Permission permission : permissionList) {
					permNotParse = 1;
					permission.setFileId(fileinfo.getId());
					permission.setUid(java.util.UUID.randomUUID().toString());
					permission.setGroupId(groupId);

					CustPermission cp = new CustPermission();
					cp.setCnName(permission.getCnName());
					cp.setDescription(permission.getDescription());
					cp.setEnName(permission.getEnName());
					cp.setFileId(permission.getFileId());
					cp.setGroupId(permission.getGroupId());
					cp.setId(permission.getId());
					cp.setUid(permission.getUid());
					cp.setPermissionPackage(permission.getPermissionPackage());
					cp.setVersionId(permission.getVersionId());

					custPermissionService.addCustPermission(cp);
				}
				int recNotParse = 0;
				List<Resource> resourceList = parserOrg.parseResource(f
						.getAbsolutePath()); // 解析并存储资源
				for (Resource resource : resourceList) {
					recNotParse = 1;
					resource.setFileId(fileinfo.getId());
					resource.setUid(java.util.UUID.randomUUID().toString());
					resource.setGroupId(groupId);

					CustResource cr = new CustResource();
					cr.setCnName(resource.getCnName());
					cr.setDescription(resource.getDescription());
					cr.setEnName(resource.getEnName());
					cr.setFileId(resource.getFileId());
					cr.setGroupId(resource.getGroupId());
					cr.setId(resource.getId());
					cr.setUid(resource.getUid());
					cr.setFunctionId(resource.getFunctionId());
					cr.setMethodName(resource.getMethodName());
					cr.setServiceName(resource.getServiceName());
					cr.setVersionId(resource.getVersionId());

					custResourceService.addCustResource(cr);
				}
				int roleNotParse = 0;
				List<Role> roleList = parserOrg.parseRole(f.getAbsolutePath()); // 解析并存储角色
				for (Role role : roleList) {

					roleNotParse = 1;
					role.setFileId(fileinfo.getId());
					role.setUid(java.util.UUID.randomUUID().toString());
					role.setGroupId(groupId);

					CustRole cr = new CustRole();

					cr.setCnName(role.getCnName());
					cr.setDescription(role.getDescription());
					cr.setEnName(role.getEnName());
					cr.setFileId(role.getFileId());
					cr.setGroupId(role.getGroupId());
					cr.setId(role.getId());
					cr.setUid(role.getUid());
					cr.setParentRoleId(role.getParentRoleId());
					cr.setVersionId(role.getVersionId());
					cr.setDepartmentid(role.getDepartmentid());
					cr.setRolePackage(role.getRolePackage());
					cr.setRoleType(role.getRoleType());

					custRoleService.addCustRole(cr);
				}

				if (roleNotParse == 1 && permNotParse == 1) {
					List<Rolepermissions> rolepermissionsList = parserOrg
							.parseRolepermissions(f.getAbsolutePath()); // 解析并存储角色权限
					for (Rolepermissions rolepermissions : rolepermissionsList) {
						rolepermissions.setGroupId(groupId);

						CustRolepermissions cr = new CustRolepermissions();

						cr.setGroupId(rolepermissions.getGroupId());
						cr.setId(rolepermissions.getId());
						cr.setVersionId(rolepermissions.getVersionId());
						cr.setPermissionid(rolepermissions.getPermissionid());
						cr.setRoleid(rolepermissions.getRoleid());

						custRolepermissionsService.addCustRolepermissions(cr);
					}

				}

				if (permNotParse == 1 && recNotParse == 1) {
					List<Permissionresources> permissionresourcesList = parserOrg
							.parsePermissionresources(f.getAbsolutePath());
					for (Permissionresources permissionresources : permissionresourcesList) {
						permissionresources.setGroupId(groupId);// 解析并纯初权限资源

						CustPermissionresources cp = new CustPermissionresources();

						cp.setGroupId(permissionresources.getGroupId());
						cp.setId(permissionresources.getId());
						cp.setVersionId(permissionresources.getVersionId());
						cp.setPermissionid(permissionresources
								.getPermissionid());
						cp.setResourceid(permissionresources.getResourceid());

						custPermissionresourcesService
								.addCustPermissionresources(cp);
					}

				}
				this.success = true;
			}
		}
		for (File f : mp.epcFiles) {
			CustFileinfo fileinfo = new CustFileinfo();
			fileinfo.setXmlpath(f.getAbsolutePath());
			fileinfo.setName(f.getName());
			fileinfo.setId(java.util.UUID.randomUUID().toString());
			fileinfo.setProject(group);
			fileinfo.setType(5);
			fileinfo.setGroupId(groupId);

			custFileInfoService.saveCustFileInfo(fileinfo);
			checkConsistenceForCust.add(fileinfo);

			String result = this.checkEpcConsistenceForCust(
					f.getAbsolutePath(), domainStateEPC, functionEpc);

			tmpresult += result; // 检测EPC模型一致性

		}	
		

		this.success = true;
		return groupId;
	}

	public String uploadFiles() throws SAXException,
			ParserConfigurationException {
		String rootPath = getSession().getServletContext().getRealPath("/");
		rootPath += ROOT;
		DefaultSecurityManager securityManager = new DefaultSecurityManager();
		securityManager.setRealm(myRealm);
		SecurityUtils.setSecurityManager(securityManager);

		Subject currentUser = SecurityUtils.getSubject();
		boolean admin = currentUser.hasRole("superadmin");

		// 解压文件，获得模型文件集合

		ModelPackage mp = new ModelPackage(myUpload, rootPath);
		admin = true;
		if (admin) {
			try {
				String uploadFileName = getMyUploadFileName();

				// 把文件名和文件ID写进FileInfo
				Fileinfo fileInfo = new Fileinfo();
				fileInfo.setId(java.util.UUID.randomUUID().toString());
				fileInfo.setName(uploadFileName);// 临时文件名
				int last = getPath().lastIndexOf("\\");

				fileInfo.setProject(getPath().substring(0, last));
				String groupId;
				int groupInt;
				List<Modelgroup> mgList = modelgroupService.getByName(fileInfo
						.getProject()); // 查看是否是已存模型
				if (mgList.toString() == "[]") {
					Modelgroup modelgroup = new Modelgroup();

					String des = getPath().substring(last + 1,
							getPath().length());
					if (des.length() != 0) {
						modelgroup.setDescription(des);
					}

					modelgroup.setGroupName(fileInfo.getProject());
					modelgroupService.save(modelgroup,Constants.ADMIN_COMPANY_ID);
					mgList = modelgroupService.getByName(fileInfo.getProject()); // 查看是否是已存模型
				}
				groupInt = mgList.get(0).getId();
				groupId = groupInt + "";

				// fileInfo.setCompany(user_company);

				// if (list.toString()=="[]"){

				String sp = rootPath + getPath().substring(0, last + 1);

				MyUtils.mkDirectory(sp);
				String path = sp + uploadFileName;

				int in = path.lastIndexOf("\\");
				String temp = path.substring(0, in + 1);
				String newDir = temp.concat("department\\");
				MyUtils.mkDirectory(newDir);
				MyUtils.upload(uploadFileName, newDir, getMyUpload());
				String newPath = newDir + path.substring(in + 1, path.length());

				fileInfo.setXmlpath(newPath);
				int type = parseFileType(fileInfo.getXmlpath());
				fileInfo.setType(type);
				fileInfo.setGroupId(groupId);
				FileAction.checkDepartment.add(fileInfo); // 把上传的文件存储到组织上传列表

				if (type == 3) {

					List<Fileinfo> isExist = fileInfoService.findFileId(
							fileInfo.getName(), fileInfo.getProject(), 3); // 先根据名称和项目查询
																			// 是否已存在类似项目
					if (isExist.toString() == "[]") {
						fileInfoService.saveFileInfo(fileInfo,Constants.ADMIN_COMPANY_ID);

						int deptNotParse = 0;
						ParserOrg parserOrg = new ParserOrg();
						List<Department> departmentList = parserOrg
								.parseDepartment(newPath); // 解析并存储部门
						for (Department department : departmentList) {
							// if
							// (departmentService.getDepartmentById(department.getId()).toString()=="[]"){

							department.setFileId(fileInfo.getId());
							department.setUid(java.util.UUID.randomUUID()
									.toString());
							department.setGroupId(groupId);
							deptNotParse = 1;
							// }

						}
						if (deptNotParse == 1)
							departmentService.save(departmentList,Constants.ADMIN_COMPANY_ID);
						int permNotParse = 0;
						List<Permission> permissionList = parserOrg
								.parsePermission(newPath); // 解析并存储权限
						for (Permission permission : permissionList) {
							// if
							// (permissionService.getPermissionById(permission.getId()).toString()=="[]"){
							permNotParse = 1;
							permission.setFileId(fileInfo.getId());
							permission.setUid(java.util.UUID.randomUUID()
									.toString());
							permission.setGroupId(groupId);
							permissionService.addPermission(permission,Constants.ADMIN_COMPANY_ID);
							// }

						}
						int recNotParse = 0;
						List<Resource> resourceList = parserOrg
								.parseResource(newPath); // 解析并存储资源
						for (Resource resource : resourceList) {
							// if
							// (resourceService.getResourceById(resource.getId()).toString()=="[]"){
							recNotParse = 1;
							resource.setFileId(fileInfo.getId());
							resource.setUid(java.util.UUID.randomUUID()
									.toString());
							resource.setGroupId(groupId);
							resourceService.addResource(resource,Constants.ADMIN_COMPANY_ID);
							// }

						}
						int roleNotParse = 0;
						List<Role> roleList = parserOrg.parseRole(newPath); // 解析并存储角色
						for (Role role : roleList) {

							// if
							// (roleService.getRoleListById(role.getId()).toString()=="[]"){
							roleNotParse = 1;
							role.setFileId(fileInfo.getId());
							role.setUid(java.util.UUID.randomUUID().toString());
							role.setGroupId(groupId);
							roleService.addRole(role,Constants.ADMIN_COMPANY_ID);
							// }
						}

						if (roleNotParse == 1 && permNotParse == 1) {
							List<Rolepermissions> rolepermissionsList = parserOrg
									.parseRolepermissions(newPath); // 解析并存储角色权限
							for (Rolepermissions rolepermissions : rolepermissionsList) {
								rolepermissions.setGroupId(groupId);
								rolepermissionsService
										.addRolepermissions(rolepermissions,Constants.ADMIN_COMPANY_ID);
							}

						}

						if (permNotParse == 1 && recNotParse == 1) {
							List<Permissionresources> permissionresourcesList = parserOrg
									.parsePermissionresources(newPath);
							for (Permissionresources permissionresources : permissionresourcesList) {
								permissionresources.setGroupId(groupId);// 解析并纯初权限资源
								permissionresourcesService
										.addPermissionresources(permissionresources,Constants.ADMIN_COMPANY_ID);
							}

						}

					}

				}
				this.success = true;

			} catch (RuntimeException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
		} else {
			uploadFilesForCust();
		}
		return SUCCESS;

	}

	public void uploadFilesForCust() throws SAXException,
			ParserConfigurationException {
		String rootPath = getSession().getServletContext().getRealPath("/");
		rootPath += ROOT;
		DefaultSecurityManager securityManager = new DefaultSecurityManager();
		securityManager.setRealm(myRealm);
		SecurityUtils.setSecurityManager(securityManager);

		try {
			String uploadFileName = getMyUploadFileName();

			// 把文件名和文件ID写进FileInfo
			CustFileinfo fileInfo = new CustFileinfo();
			fileInfo.setId(java.util.UUID.randomUUID().toString());
			fileInfo.setName(uploadFileName);// 临时文件名
			int last = getPath().lastIndexOf("\\");
			int first = last + 1;
			fileInfo.setProject(getPath().substring(0, last));
			Integer groupId = -1;

			List<CustModelgroup> mgList = custModelgroupService
					.getByName(fileInfo.getProject()); // 查看是否是已存模型
			if (mgList.toString() == "[]") {
				CustModelgroup modelgroup = new CustModelgroup();

				String des = getPath().substring(last + 1, getPath().length());
				if (des.length() != 0) {
					modelgroup.setDescription(des);
				}

				modelgroup.setGroupName(fileInfo.getProject());
				Modelgroup mg=new Modelgroup();
				PropertyHelper.copyProperties(modelgroup, mg);
				groupId = modelgroupService.save(mg,1);
			} else {
				groupId = mgList.get(0).getId();
			}

			// fileInfo.setCompany(user_company);

			// if (list.toString()=="[]"){

			String sp = rootPath + getPath().substring(0, last + 1);

			MyUtils.mkDirectory(sp);
			String path = sp + fileInfo.getName(); // 上传后的名字不改变

			int in = path.lastIndexOf("\\");
			String temp = path.substring(0, in + 1);
			String newDir = temp.concat("department\\");
			MyUtils.mkDirectory(newDir);
			MyUtils.upload(fileInfo.getName(), newDir, getMyUpload()); // 上传名字不改变
			String newPath = newDir + path.substring(in + 1, path.length());

			fileInfo.setXmlpath(newPath);
			int type = parseFileType(fileInfo.getXmlpath());
			fileInfo.setType(type);
			fileInfo.setGroupId("" + groupId);
			FileAction.checkCustDepartment.add(fileInfo); // 把上传的文件存储到组织上传列表

			if (type == 3) {

				List<CustFileinfo> isExist = custFileInfoService.findFileId(
						fileInfo.getName(), fileInfo.getProject(), 3); // 先根据名称和项目查询
																		// 是否已存在类似项目
				if (isExist.toString() == "[]") {
					custFileInfoService.saveCustFileInfo(fileInfo);

					int deptNotParse = 0;
					ParserOrg parserOrg = new ParserOrg();
					List<Department> departmentList = parserOrg
							.parseDepartment(newPath); // 解析并存储部门
					List<CustDepartment> cdlist = new ArrayList<CustDepartment>();
					for (Department d : departmentList) {
						// if
						// (departmentService.getDepartmentById(department.getId()).toString()=="[]"){

						CustDepartment department = new CustDepartment(
								d.getId(), d.getCnName(), d.getEnName(),
								d.getParentName(), d.getFileId(),
								d.getGroupId(), d.getUid(),d.getVersionId());

						department.setFileId(fileInfo.getId());
						department.setUid(java.util.UUID.randomUUID()
								.toString());
						department.setGroupId(groupId + "");
						department.setVersionId(fileInfo.getVersionId());
						deptNotParse = 1;
						// }
						cdlist.add(department);

					}
					if (deptNotParse == 1)
						custDepartmentService.save(cdlist);
					int permNotParse = 0;
					List<Permission> permissionList = parserOrg
							.parsePermission(newPath); // 解析并存储权限
					List<CustPermission> cplist = new ArrayList<CustPermission>();
					for (Permission p : permissionList) {
						// if
						// (permissionService.getPermissionById(permission.getId()).toString()=="[]"){
						CustPermission permission = new CustPermission();
						permission.setId(p.getId());
						permission.setCnName(p.getCnName());
						permission.setDescription(p.getDescription());
						permission.setEnName(p.getEnName());
						permission.setFileId(p.getFileId());
						permission.setGroupId(p.getGroupId());
						permission.setPermissionPackage(p
								.getPermissionPackage());
						permission.setUid(p.getUid());
						permission.setVersionId(p.getVersionId());

						permNotParse = 1;
						permission.setFileId(fileInfo.getId());
						permission.setUid(java.util.UUID.randomUUID()
								.toString());
						permission.setGroupId(groupId.toString());
						custPermissionService.addCustPermission(permission);
						// }
						cplist.add(permission);

					}
					int recNotParse = 0;
					List<Resource> resourceList = parserOrg
							.parseResource(newPath); // 解析并存储资源
					List<CustResource> crlist = new ArrayList<CustResource>();
					for (Resource r : resourceList) {
						// if
						// (resourceService.getResourceById(resource.getId()).toString()=="[]"){
						CustResource resource = new CustResource();
						resource.setId(r.getId());
						resource.setEnName(r.getEnName());
						resource.setCnName(r.getCnName());
						resource.setDescription(r.getDescription());
						resource.setServiceName(r.getServiceName());
						resource.setMethodName(r.getMethodName());
						resource.setFunctionId(r.getFunctionId());
						resource.setFileId(r.getFileId());
						resource.setVersionId(r.getVersionId());
						resource.setUid(r.getUid());

						recNotParse = 1;
						resource.setFileId(fileInfo.getId());
						resource.setUid(java.util.UUID.randomUUID().toString());
						resource.setGroupId(groupId.toString());
						custResourceService.addCustResource(resource);
						// }
						crlist.add(resource);

					}
					int roleNotParse = 0;
					List<Role> roleList = parserOrg.parseRole(newPath); // 解析并存储角色
					List<CustRole> crolelist = new ArrayList<CustRole>();
					for (Role r : roleList) {
						CustRole role = new CustRole();
						role.setCnName(r.getCnName());
						role.setDepartmentid(r.getDepartmentid());
						role.setDescription(r.getDescription());
						role.setEnName(r.getEnName());
						role.setFileId(r.getFileId());
						role.setGroupId(r.getGroupId());
						role.setId(r.getId());
						role.setParentRoleId(r.getParentRoleId());
						role.setRolePackage(r.getRolePackage());
						role.setRoleType(r.getRoleType());
						role.setUid(r.getUid());
						role.setVersionId(r.getVersionId());

						// if
						// (roleService.getRoleListById(role.getId()).toString()=="[]"){
						roleNotParse = 1;
						role.setFileId(fileInfo.getId());
						role.setUid(java.util.UUID.randomUUID().toString());
						role.setGroupId(groupId.toString());
						custRoleService.addCustRole(role);
						// }

						crolelist.add(role);
					}

					if (roleNotParse == 1 && permNotParse == 1) {
						List<Rolepermissions> rolepermissionsList = parserOrg
								.parseRolepermissions(newPath); // 解析并存储角色权限
						for (Rolepermissions rolepermissions : rolepermissionsList) {
							CustRolepermissions cr = new CustRolepermissions();
							cr.setId(rolepermissions.getId());
							cr.setPermissionid(rolepermissions
									.getPermissionid());
							cr.setRoleid(rolepermissions.getRoleid());
							cr.setVersionId(rolepermissions.getVersionId());

							cr.setGroupId(groupId.toString());
							custRolepermissionsService
									.addCustRolepermissions(cr);
						}

					}

					if (permNotParse == 1 && recNotParse == 1) {
						List<Permissionresources> permissionresourcesList = parserOrg
								.parsePermissionresources(newPath);
						for (Permissionresources permissionresources : permissionresourcesList) {
							CustPermissionresources cp = new CustPermissionresources();
							cp.setId(permissionresources.getId());
							cp.setPermissionid(permissionresources
									.getPermissionid());
							cp.setResourceid(permissionresources
									.getResourceid());
							cp.setVersionId(permissionresources.getVersionId());

							cp.setGroupId(groupId.toString());// 解析并纯初权限资源
							custPermissionresourcesService
									.addCustPermissionresources(cp);
						}

					}

				}

			}
			this.success = true;

		} catch (RuntimeException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public String uploadOtherFiles() {
		String rootPath = getSession().getServletContext().getRealPath("/");

		rootPath += ROOT;
		String sp = rootPath + getPath();
		System.out.println(sp);
		MyUtils.mkDirectory(sp);
		DefaultSecurityManager securityManager = new DefaultSecurityManager();
		securityManager.setRealm(myRealm);
		SecurityUtils.setSecurityManager(securityManager);
		Subject cuser = SecurityUtils.getSubject();
		boolean admin = cuser.hasRole("superadmin");
		admin = true;
		
		if (admin) {
			try {

				String uploadFileName = getMyUploadFileName();

				Fileinfo fileInfo = new Fileinfo();
				fileInfo.setId(java.util.UUID.randomUUID().toString());
				fileInfo.setName(uploadFileName);// 临时文件名
				fileInfo.setXmlpath(sp + fileInfo.getName()); // 上传名字不改变

				fileInfo.setType(0);

				MyUtils.upload(fileInfo.getName(), sp, getMyUpload()); // 上传名字不改变
				id = fileInfo.getId();

				type = parseFileType(fileInfo.getXmlpath());
				fileInfo.setType(type);
				FileAction.checkConsistence.add(fileInfo); // 上传到一致性检测列表

				if (type != 0) {

					fileInfoService.saveFileInfo(fileInfo,Constants.ADMIN_COMPANY_ID); // 存储fileinfo
				}
				this.success = true;

			} catch (RuntimeException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
		} else {
			uploadOtherFilesForCust();
		}	
		
		return SUCCESS;

	}

	public void uploadOtherFilesForCust() {
		String rootPath = getSession().getServletContext().getRealPath("/");

		rootPath += ROOT;
		String sp = rootPath + getPath();
		System.out.println(sp);
		MyUtils.mkDirectory(sp);
		DefaultSecurityManager securityManager = new DefaultSecurityManager();
		securityManager.setRealm(myRealm);
		SecurityUtils.setSecurityManager(securityManager);

		try {

			String uploadFileName = getMyUploadFileName();

			CustFileinfo fileInfo = new CustFileinfo();
			fileInfo.setId(java.util.UUID.randomUUID().toString());
			fileInfo.setName(uploadFileName);// 临时文件名
			fileInfo.setXmlpath(sp + fileInfo.getName()); // 上传名字不改变
			int last = getPath().lastIndexOf("\\");

			fileInfo.setProject(getPath().substring(0, last));

			MyUtils.upload(fileInfo.getName(), sp, getMyUpload()); // 上传名字不改变
			id = fileInfo.getId();

			type = parseFileType(fileInfo.getXmlpath());
			fileInfo.setType(type);
			FileAction.checkConsistenceForCust.add(fileInfo); // 上传到一致性检测列表

			if (type != 0) {

				custFileInfoService.saveCustFileInfo(fileInfo); // 存储fileinfo
			}
			this.success = true;

		} catch (RuntimeException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public String checkConsistence() {
		List<Fileinfo> fileList = FileAction.getCheckConsistence(); // 改成用名称和项目查询
		int a[] = { 0, 0, 0, 0 };
		List<Fileinfo> processIndex = new ArrayList<Fileinfo>();
		List<Fileinfo> functionIndex = new ArrayList<Fileinfo>();
		List<Fileinfo> otherIndex = new ArrayList<Fileinfo>();
		List<Fileinfo> domainModelIndex = new ArrayList<Fileinfo>();
		List<Fileinfo> epcIndex = new ArrayList<Fileinfo>();

		for (Fileinfo file : fileList) {
			try {
				int type = parseFileType(file.getXmlpath());
				switch (type) {
				case 1: {
					a[0] = 1;
					processIndex.add(file);
					break;
				}
				case 2: {
					a[1] = 1;
					functionIndex.add(file);
					break;
				}
				case 4: {
					a[2] = 1;
					domainModelIndex.add(file);
					break;
				}
				case 5: {
					a[3] = 1;
					epcIndex.add(file);
					break;
				}
				default: {
					otherIndex.add(file);
					break;
				}
				}
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		if (a[0] == 0)
			isConsistence += "流程模型 ";
		if (a[1] == 0)
			isConsistence += "功能模型 ";
		if (a[2] == 0)
			isConsistence += "业务对象模型 "; // 检测是否所有类型的文件都已上传
		if (a[3] == 0)
			isConsistence += "epc模型 ";
		if (otherIndex.size() != 0) {
			for (Fileinfo i : otherIndex) {
				isConsistence += "~警告：" + i.getName() + "文件类型不符合要求，服务器已删除文件"; // 删除不合格的文件
				MyUtils.deleteFile(i.getXmlpath());

			}
		}
		if (isConsistence.equals("~错误：请上传"))
			isConsistence = "";
		List<Domainmodelstate> domainStateEPC = new ArrayList<Domainmodelstate>();
		for (Fileinfo i : domainModelIndex) {
			try {

				ParseDomainModel pdm = new ParseDomainModel();
				ArrayList<Domainmodelstate> dmodelstate = pdm.reserveState(i
						.getXmlpath()); // 抽取所有业务对象模型的状态模型
				for (Domainmodelstate ds : dmodelstate) {
					domainStateEPC.add(ds);
				}
				if (checkDM(i.getXmlpath()) != "") {
					isConsistence += "~错误：" + checkDM(i.getXmlpath())
							+ "业务对象文件没有上传"; // 检测复杂业务对象模型 看是否都已上传
				}

			} catch (ParserConfigurationException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (SAXException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();

			}
		}

		HashMap<String, Integer> functionPoint = new HashMap<String, Integer>();
		List<Functionpoint> functionEpc = new ArrayList<Functionpoint>();
		for (Fileinfo j : functionIndex) {
			ParserFunctionpoint pfp = new ParserFunctionpoint();
			Functionpoint fp = pfp.reservePoint(j.getXmlpath()); // 抽取所有功能点
			functionPoint.put(fp.getId(), 0);
			functionEpc.add(fp);
		}
		for (Fileinfo i : processIndex) {
			ParserProcess pp = new ParserProcess();
			ArrayList<Functions> fs = pp.reserveFunctions(i.getXmlpath());
			for (Functions functions : fs) { // 检测流程文件的功能点是否都已上传
				String fId = functions.getFunctionid();
				if (functionPoint.containsKey(fId))
					functionPoint.put(fId, 1);
				else
					isConsistence += "~错误：" + fId + "功能文件没有上传";
			}
		}

		if (functionPoint.containsValue(0)) {
			isConsistence += "~警告：";
			// 采用Iterator遍历HashMap
			Iterator it = functionPoint.keySet().iterator();
			while (it.hasNext()) {

				String key = (String) it.next();

				if (functionPoint.get(key) == 0)
					isConsistence += key + " ";
			}
			isConsistence += "没有对应的流程文件，请检查是否还有未上传的流程文件"; // 检测是否有未包含在流程的功能点模型

		}
		for (Fileinfo i : epcIndex) {
			String result = this.checkEpcConsistence(i.getXmlpath(),
					domainStateEPC, functionEpc);

			isConsistence += result; // 检测EPC模型一致性
		}

		if (isConsistence == "") {
			FileAction.getCheckConsistence().removeAll(
					FileAction.checkConsistence);
			FileAction.setCheckConsistence(FileAction.checkConsistence);// 检测完后
																		// 把带检测文件清空
		}
		return SUCCESS;
	}
	
	public String checkConsistenceForCust() {
		List<CustFileinfo> fileList = FileAction.getCheckConsistenceForCust(); // 改成用名称和项目查询
		int a[] = { 0, 0, 0, 0 };
		List<CustFileinfo> processIndex = new ArrayList<CustFileinfo>();
		List<CustFileinfo> functionIndex = new ArrayList<CustFileinfo>();
		List<CustFileinfo> otherIndex = new ArrayList<CustFileinfo>();
		List<CustFileinfo> domainModelIndex = new ArrayList<CustFileinfo>();
		List<CustFileinfo> epcIndex = new ArrayList<CustFileinfo>();

		for (CustFileinfo file : fileList) {
			try {
				int type = parseFileType(file.getXmlpath());
				switch (type) {
				case 1: {
					a[0] = 1;
					processIndex.add(file);
					break;
				}
				case 2: {
					a[1] = 1;
					functionIndex.add(file);
					break;
				}
				case 4: {
					a[2] = 1;
					domainModelIndex.add(file);
					break;
				}
				case 5: {
					a[3] = 1;
					epcIndex.add(file);
					break;
				}
				default: {
					otherIndex.add(file);
					break;
				}
				}
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		if (a[0] == 0)
			isConsistence += "流程模型 ";
		if (a[1] == 0)
			isConsistence += "功能模型 ";
		if (a[2] == 0)
			isConsistence += "业务对象模型 "; // 检测是否所有类型的文件都已上传
		if (a[3] == 0)
			isConsistence += "epc模型 ";
		if (otherIndex.size() != 0) {
			for (CustFileinfo i : otherIndex) {
				isConsistence += "~警告：" + i.getName() + "文件类型不符合要求，服务器已删除文件"; // 删除不合格的文件
				MyUtils.deleteFile(i.getXmlpath());

			}
		}
		if (isConsistence.equals("~错误：请上传"))
			isConsistence = "";
		List<CustDomainmodelstate> domainStateEPC = new ArrayList<CustDomainmodelstate>();
		for (CustFileinfo i : domainModelIndex) {
			try {

				ParseDomainModel pdm = new ParseDomainModel();
				ArrayList<Domainmodelstate> dmodelstate = pdm.reserveState(i
						.getXmlpath()); // 抽取所有业务对象模型的状态模型
				for (Domainmodelstate ds : dmodelstate) {
					CustDomainmodelstate cds=new CustDomainmodelstate(ds);
					domainStateEPC.add(cds);
				}
				if (checkDM(i.getXmlpath()) != "") {
					isConsistence += "~错误：" + checkDM(i.getXmlpath())
							+ "业务对象文件没有上传"; // 检测复杂业务对象模型 看是否都已上传
				}

			} catch (ParserConfigurationException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (SAXException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();

			}
		}

		HashMap<String, Integer> functionPoint = new HashMap<String, Integer>();
		List<CustFunctionpoint> functionEpc = new ArrayList<CustFunctionpoint>();
		for (CustFileinfo j : functionIndex) {
			ParserFunctionpoint pfp = new ParserFunctionpoint();
			Functionpoint fp = pfp.reservePoint(j.getXmlpath()); // 抽取所有功能点
			functionPoint.put(fp.getId(), 0);
			CustFunctionpoint cfp=new CustFunctionpoint(fp);
			functionEpc.add(cfp);
		}
		for (CustFileinfo i : processIndex) {
			ParserProcess pp = new ParserProcess();
			ArrayList<Functions> fs = pp.reserveFunctions(i.getXmlpath());
			for (Functions functions : fs) { // 检测流程文件的功能点是否都已上传
				String fId = functions.getFunctionid();
				if (functionPoint.containsKey(fId))
					functionPoint.put(fId, 1);
				else
					isConsistence += "~错误：" + fId + "功能文件没有上传";
			}
		}

		if (functionPoint.containsValue(0)) {
			isConsistence += "~警告：";
			// 采用Iterator遍历HashMap
			Iterator it = functionPoint.keySet().iterator();
			while (it.hasNext()) {

				String key = (String) it.next();

				if (functionPoint.get(key) == 0)
					isConsistence += key + " ";
			}
			isConsistence += "没有对应的流程文件，请检查是否还有未上传的流程文件"; // 检测是否有未包含在流程的功能点模型

		}
		for (CustFileinfo i : epcIndex) {
			String result = this.checkEpcConsistenceForCust(i.getXmlpath(),
					domainStateEPC, functionEpc);

			isConsistence += result; // 检测EPC模型一致性
		}

		if (isConsistence == "") {
			FileAction.getCheckConsistenceForCust().removeAll(
					FileAction.checkConsistenceForCust);
			FileAction.setCheckConsistenceForCust(FileAction.checkConsistenceForCust);// 检测完后
																		// 把带检测文件清空
		}
		return SUCCESS;
	}

	public String checkEpcConsistence(String xmlPath,
			List<Domainmodelstate> stateList, List<Functionpoint> functionList) {
		String result = "";
		HashMap<String, Integer> stateMap = new HashMap<String, Integer>();
		HashMap<String, Integer> functionMap = new HashMap<String, Integer>();
		for (Domainmodelstate ds : stateList) {
			stateMap.put(ds.getId(), 0);
		}
		for (Functionpoint fp : functionList) {
			functionMap.put(fp.getId(), 0);
		}
		Epcunits epcunits;
		try {
			epcunits = ParserEpc.parse(xmlPath);
			List<Epcunit> list = epcunits.getEpcUnits();
			for (Epcunit epcunit : list) {
				if (epcunit.getType() == "event") {
					String eName = epcunit.getName();
					int find = 0;
					for (Domainmodelstate ds : stateList) {
						if (ds.getEnName().equals(eName)) {
							find = 1;
							stateMap.put(ds.getId(), 1);
							break;
						}
					}
					if (find == 0)
						result += "状态" + eName + " "; // epcunit 没有找到类似的单元

				}
				if (epcunit.getType() == "function") {
					String fName = epcunit.getName();
					int find = 0;
					for (Functionpoint fp : functionList) {
						if (fp.getEnName().equals(fName)) {
							find = 1;
							functionMap.put(fp.getId(), 1);
							break;
						}
					}
					if (find == 0)
						result += "功能" + fName + " ";
				}

			}
			if (result != "")
				result = "~错误：" + result + "没有找到对应的上传模型";
			if (functionMap.containsValue(0)) {
				// 采用Iterator遍历HashMap
				Iterator it = functionMap.keySet().iterator();
				while (it.hasNext()) {

					String key = (String) it.next();

					if (functionMap.get(key) == 0)
						result += key + " ";
				}
				result = "~警告：" + result + "没有找到对应的功能模型，请检查是否还有未上传的EPC文件";
			}
			if (stateMap.containsValue(0)) {
				// 采用Iterator遍历HashMap
				Iterator it = stateMap.keySet().iterator();
				while (it.hasNext()) {

					String key = (String) it.next();

					if (stateMap.get(key) == 0)
						result += key + " ";
				}
				result = "~警告：" + result + "没有找到对应的事件模型，请检查是否还有未上传的EPC文件";

			}

		} catch (SAXException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ParserConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;

	}

	public String checkEpcConsistenceForCust(String xmlPath,
			List<CustDomainmodelstate> stateList,
			List<CustFunctionpoint> functionList) {
		String result = "";
		HashMap<String, Integer> stateMap = new HashMap<String, Integer>();
		HashMap<String, Integer> functionMap = new HashMap<String, Integer>();
		for (CustDomainmodelstate ds : stateList) {
			stateMap.put(ds.getId(), 0);
		}
		for (CustFunctionpoint fp : functionList) {
			functionMap.put(fp.getId(), 0);
		}
		CustEpcunits epcunits;
		try {
			epcunits = ParserEpc.parseForCust(xmlPath);
			List<CustEpcunit> list = epcunits.epcunitList();
			for (CustEpcunit epcunit : list) {
				if (epcunit.getType() == "event") {
					String eName = epcunit.getName();
					int find = 0;
					for (CustDomainmodelstate ds : stateList) {
						if (ds.getEnName().equals(eName)) {
							find = 1;
							stateMap.put(ds.getId(), 1);
							break;
						}
					}
					if (find == 0)
						result += "状态" + eName + " "; // epcunit 没有找到类似的单元

				}
				if (epcunit.getType() == "function") {
					String fName = epcunit.getName();
					int find = 0;
					for (CustFunctionpoint fp : functionList) {
						if (fp.getEnName().equals(fName)) {
							find = 1;
							functionMap.put(fp.getId(), 1);
							break;
						}
					}
					if (find == 0)
						result += "功能" + fName + " ";
				}

			}
			if (result != "")
				result = "~错误：" + result + "没有找到对应的上传模型";
			if (functionMap.containsValue(0)) {
				// 采用Iterator遍历HashMap
				Iterator it = functionMap.keySet().iterator();
				while (it.hasNext()) {

					String key = (String) it.next();

					if (functionMap.get(key) == 0)
						result += key + " ";
				}
				result = "~警告：" + result + "没有找到对应的功能模型，请检查是否还有未上传的EPC文件";
			}
			if (stateMap.containsValue(0)) {
				// 采用Iterator遍历HashMap
				Iterator it = stateMap.keySet().iterator();
				while (it.hasNext()) {

					String key = (String) it.next();

					if (stateMap.get(key) == 0)
						result += key + " ";
				}
				result = "~警告：" + result + "没有找到对应的事件模型，请检查是否还有未上传的EPC文件";

			}

		} catch (SAXException e) {
			// TODO Auto-generated catch block
			System.out.println("SAXException："+xmlPath);
			return "";
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ParserConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;

	}

	// 解析文件类型
	public int parseFileType(String filePath) throws IOException {
		int type = 0;
		FileReader fr = new FileReader(filePath);
		BufferedReader reader = new BufferedReader(fr);
		if (reader.ready()) {
			String line = reader.readLine();
			if ((line.subSequence(1, line.length() - 1)).toString().equals(
					"business_process")) {
				type = 1;// "流程模型";
			} else if ((line.subSequence(1, line.length() - 1)).toString()
					.equals("function_point")) {
				type = 2;// "功能模型";
			} else if (line.contains("organization")) {
				type = 3; // "组织模型"
			} else if ((line.subSequence(1, line.length() - 1)).toString()
					.equals("permission")) {
				type = 6;// "权限模型";
			} else if ((line.subSequence(1, line.length() - 1)).toString()
					.equals("domain_model")) {
				type = 4;// "业务对象模型";
			} else if ((line.subSequence(1, line.length() - 1)).toString()
					.equals("role")) {
				type = 7;// "角色模型";

			} else if (line.contains("epml")) {
				type = 5;// "EPC模型";

			} else {
				type = 0;// "无模型";
				String line2 = reader.readLine();
				if (line2.contains("epml")) {
					type = 5;// "EPC模型";
				}
			}
		}
		reader.close();
		fr.close();
		return type;
	}

	public String checkDM(String xmlPath) throws ParserConfigurationException,
			SAXException, IOException { // get children path
		String result = "";
		List<Fileinfo> fileList = FileAction.getCheckConsistence();
		int in = xmlPath.lastIndexOf("\\");
		String name = xmlPath.substring(in + 1, xmlPath.length());

		DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
		DocumentBuilder db = dbf.newDocumentBuilder();
		File file = new File(xmlPath); // path should definite correct
		Document doc = db.parse(file);
		NodeList nodelist = doc.getElementsByTagName("domain_model_attribute"); // get
																				// the
																				// child
																				// path
																				// from
																				// current
																				// xml
		for (int i = 0; i < nodelist.getLength(); i++) {
			Element dma = (Element) nodelist.item(i);
			NodeList str = dma.getElementsByTagName("typeId");
			Element paramElement = (Element) str.item(0);
			Text paramNode = (Text) paramElement.getFirstChild();
			String str1 = paramNode.getNodeValue();
			if (str1.length() > 2) { // 是个复杂类型的业务对象
				str1+=".xml";
				int find = 0;
				for (Fileinfo fileinfo : fileList) {
					if (fileinfo.getName().equals(str1)) {
						find = 1;
						
					}
				}
				if (find == 0)
					result += str1 + " ";
			}
		}
		return result;

	}

	public String deleteDeptUpload() {
		List<Fileinfo> fileList = FileAction.getCheckDepartment();
		for (Fileinfo fileinfo : fileList) {
			if (fileinfo.getName().equals(this.fileName)) { // 删除部门候选文件列表
				int index = fileList.indexOf(fileinfo);
				fileList.remove(index);
				break;
			}
		}
		FileAction.setCheckDepartment(fileList);
		return SUCCESS;
	};

	public String deleteOtherUpload() {
		List<Fileinfo> fileList = FileAction.getCheckConsistence(); // 删除一致性文件列表
		for (Fileinfo fileinfo : fileList) {
			if (fileinfo.getName().equals(this.fileName)) {
				int index = fileList.indexOf(fileinfo);
				fileList.remove(index);
				break;
			}
		}
		FileAction.setCheckConsistence(fileList);
		return SUCCESS;
	};

	public String zipAllUpload() throws ParserConfigurationException,
			SAXException, IOException {

		DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
		DocumentBuilder db = null;
		db = dbf.newDocumentBuilder();
		
		Subject currentUser = SecurityUtils.getSubject();
		boolean admin = currentUser.hasRole("superadmin");
		
		if(admin){
			for(int i=0;i<checkConsistence.size();i++){
				Fileinfo f=checkConsistence.get(i);
			
			//for (CustFileinfo f : FileAction.tempOtherCustModel) {
				File file = new File(f.getXmlpath());
				Document doc=null;
				try{
					doc = db.parse(file);
				}catch(Exception e){
					System.out.println("zipAllUpload Exception("+e.getClass().getName()+"):"+f.getXmlpath());;
					continue;
				}
				if (f.getType() != 5) {

					NodeList nodelist = doc.getElementsByTagName("cnName"); // 获取该ID的标签

					Element node1 = (Element) nodelist.item(0); // 获取该ID标签的第一个Item

					NodeList nodelist2 = node1.getChildNodes(); // 获取该ID标签第一个Item里面的结点
					if (nodelist2.getLength() != 0) {
						f.setName(nodelist2.item(0).getNodeValue()); // 取值

					} else {
						f.setName("");
					}

				} else {
					NodeList nodelist = doc.getElementsByTagName("epc");

					NamedNodeMap head = nodelist.item(0).getAttributes();
					f.setName(head.item(1).getNodeValue());
				}

			}
			otherModel.addAll(FileAction.checkConsistence);
			zipConsistence = FileAction.tmpresult;
			tmpresult = "";
			checkConsistence.removeAll(checkConsistence);
		}else{
			for(int i=0;i<checkConsistenceForCust.size();i++){
				CustFileinfo f=checkConsistenceForCust.get(i);
			
			//for (CustFileinfo f : FileAction.tempOtherCustModel) {
				File file = new File(f.getXmlpath());
				Document doc=null;
				try{
					doc = db.parse(file);
				}catch(Exception e){
					System.out.println("zipAllUpload Exception("+e.getClass().getName()+"):"+f.getXmlpath());;
					continue;
				}
				if (f.getType() != 5) {

					NodeList nodelist = doc.getElementsByTagName("cnName"); // 获取该ID的标签

					Element node1 = (Element) nodelist.item(0); // 获取该ID标签的第一个Item

					NodeList nodelist2 = node1.getChildNodes(); // 获取该ID标签第一个Item里面的结点
					if (nodelist2.getLength() != 0) {
						f.setName(nodelist2.item(0).getNodeValue()); // 取值

					} else {
						f.setName("");
					}

				} else {
					NodeList nodelist = doc.getElementsByTagName("epc");

					NamedNodeMap head = nodelist.item(0).getAttributes();
					f.setName(head.item(1).getNodeValue());
				}

			}
			otherModel.addAll(FileAction.checkConsistenceForCust);
			zipConsistence = FileAction.tmpresult;
			tmpresult = "";
			checkConsistenceForCust.removeAll(checkConsistenceForCust);
		}
		
		return SUCCESS;
	};

	public String checkDepartment() { // 检测部门上传文件
		Subject currentUser = SecurityUtils.getSubject();
		boolean admin = currentUser.hasRole("superadmin");

		if (admin) {
			List<Fileinfo> fileList = FileAction.getCheckDepartment();
			if (fileList.size() > 1)
				isDepartment = "错误：文件上传过多 ";
			for (Fileinfo fileinfo : fileList) {
				try {
					if (parseFileType(fileinfo.getXmlpath()) != 3) {

						MyUtils.deleteFile(fileinfo.getXmlpath());

						isDepartment += "~错误：" + fileinfo.getName()
								+ "文件类型不符合要求";

					}
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();

				}
			}
			if (isDepartment == "") {
				fileList.removeAll(fileList);
				FileAction.setCheckDepartment(fileList);
			}
		} else {
			List<CustFileinfo> fileList = FileAction
					.getCheckDepartmentForCust();
			if (fileList.size() > 1)
				isDepartment = "文件上传过多 ";
			for (CustFileinfo fileinfo : fileList) {
				try {
					if (parseFileType(fileinfo.getXmlpath()) != 3) {

						MyUtils.deleteFile(fileinfo.getXmlpath());
						isDepartment += fileinfo.getName() + "文件类型不符合要求";

					}
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			if (isDepartment == "") {
				fileList.removeAll(fileList);
				FileAction.setCheckDepartmentForCust(fileList);
			}
		}

		return SUCCESS;
	}

	public String findModelName() throws ParserConfigurationException,
			SAXException, IOException {
		DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
		DocumentBuilder db = null;
		db = dbf.newDocumentBuilder();
		for (Fileinfo f : FileAction.checkConsistence) {
			if (f.getId().equals(did)) {
				File file = new File(f.getXmlpath());
				Document doc = db.parse(file);
				if (f.getType() != 5) {

					NodeList nodelist = doc.getElementsByTagName("cnName"); // 获取该ID的标签

					Element node1 = (Element) nodelist.item(0); // 获取该ID标签的第一个Item

					NodeList nodelist2 = node1.getChildNodes(); // 获取该ID标签第一个Item里面的结点
					if (nodelist2.getLength() != 0) {
						rname = nodelist2.item(0).getNodeValue(); // 取值

					} else {
						rname = "";
					}

				} else {
					NodeList nodelist = doc.getElementsByTagName("epc");

					NamedNodeMap head = nodelist.item(0).getAttributes();
					rname = head.item(1).getNodeValue();
				}

			}
		}

		return SUCCESS;
	}

	public File getMyUpload() {
		return myUpload;
	}

	public void setMyUpload(File myUpload) {
		this.myUpload = myUpload;
	}

	public String getMyUploadContentType() {
		return myUploadContentType;
	}

	public void setMyUploadContentType(String myUploadContentType) {
		this.myUploadContentType = myUploadContentType;
	}

	public String getMyUploadFileName() {
		return myUploadFileName;
	}

	public void setMyUploadFileName(String myUploadFileName) {
		this.myUploadFileName = myUploadFileName;
	}

	@JSON(name = "success")
	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) throws UnsupportedEncodingException {
		this.path = URLDecoder.decode(path, "UTF-8");
	}

	public Map<String, Object> getInfos() {
		return infos;
	}

	public void setInfos(Map<String, Object> infos) {
		this.infos = infos;
	}

	@JSON(name = "rname")
	public String getrname() {
		return rname;
	}

	@JSON(name = "isConsistence")
	public String getIsConsistence() {
		return isConsistence;
	}

	@JSON(name = "zipConsistence")
	public String getZipConsistence() {
		return zipConsistence;
	}

	@JSON(name = "isDepartment")
	public String getIsDepartment() {
		return isDepartment;
	}

	public String getId() {
		return id;
	}

	@JSON(name = "otherModel")
	public List<Fileinfo> getOtherModel() {
		return otherModel;

	}

	public void setZipConsistence(String zipConsistence) {
		this.zipConsistence = zipConsistence;
	}

	public void setOtherModel(List<Fileinfo> otherModel) {
		this.otherModel = otherModel;
	}

	@JSON(name = "totalOtherModel")
	public int getTotalOtherModel() {
		return this.otherModel.size();
	}

	@JSON(name = "id")
	public void setId(String id) {
		this.id = id;
	}

	public int getType() {
		return type;
	}

	@JSON(name = "type")
	public void setType(int type) {
		this.type = type;
	}

	public void setFileInfoService(FileInfoService fileInfoService) {
		this.fileInfoService = fileInfoService;
	}

	public void setCustFileInfoService(CustFileInfoService custFileInfoService) {
		this.custFileInfoService = custFileInfoService;
	}

	public void setMyRealm(MyRealm myRealm) {
		this.myRealm = myRealm;
	}

	/**
	 * @param shiroUserService
	 *            the shiroUserService to set
	 */
	public void setShiroUserService(ShiroUserService shiroUserService) {
		this.shiroUserService = shiroUserService;
	}

	/**
	 * @return the shiroUserService
	 */
	public ShiroUserService getShiroUserService() {
		return shiroUserService;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	/**
	 * @param repositoryMoudlService the repositoryMoudlService to set
	 */
	public void setRepositoryMoudlService(RepositoryMoudl repositoryMoudlService) {
		this.repositoryMoudlService = repositoryMoudlService;
	}

	/**
	 * @return the repositoryMoudlService
	 */
	public RepositoryMoudl getRepositoryMoudlService() {
		return repositoryMoudlService;
	}

	/**
	 * @param oplogService the oplogService to set
	 */
	public void setOplogService(OplogService oplogService) {
		this.oplogService = oplogService;
	}
}
